<?php

namespace app\traits;

trait Mobile
{
    protected $model,$pages;
    public function index(){
        $data=$this->model::order('id','desc')->paginate([
            'list_rows' =>$this->pages,
            false,
            'type'     => '\app\mobile\common\Bootstrap'
        ]);

        $this->assign([
            'data'=>$data,
        ]);
        return $this->fetch();
    }
    public function detail(){
        $id=$this->request->param('id');
        $detail=$this->model::find($id);
        $prev=$this->model::where('id','>',$id)->order('id','asc')->find();
        $next=$this->model::where('id','<',$id)->order('id','desc')->find();
        $detail->save(['views'=>$detail['views']+1]);
        $this->assign([
            'detail'=>$detail,
            'prev'=>$prev,
            'next'=>$next,
        ]);
        return $this->fetch();
    }
}